home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / lisp / clx_tar.z / clx_tar / clx / depdefs.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1993-09-07  |  22.9 KB  |  696 lines

  1. ;;; -*- Mode: LISP; Syntax: Common-lisp; Package: XLIB; Base: 10; Lowercase: Yes -*-
  2.  
  3. ;; This file contains some of the system dependent code for CLX
  4.  
  5. ;;;
  6. ;;;             TEXAS INSTRUMENTS INCORPORATED
  7. ;;;                  P.O. BOX 2909
  8. ;;;                   AUSTIN, TEXAS 78769
  9. ;;;
  10. ;;; Copyright (C) 1987 Texas Instruments Incorporated.
  11. ;;;
  12. ;;; Permission is granted to any individual or institution to use, copy, modify,
  13. ;;; and distribute this software, provided that this complete copyright and
  14. ;;; permission notice is maintained, intact, in all copies and supporting
  15. ;;; documentation.
  16. ;;;
  17. ;;; Texas Instruments Incorporated provides this software "as is" without
  18. ;;; express or implied warranty.
  19. ;;;
  20.  
  21. (in-package :xlib)
  22.  
  23. #+cmu
  24. (eval-when (compile load eval)
  25.   (let ((vs (lisp-implementation-version)))
  26.     (when (and (<= 2 (length vs))
  27.            (eql #\1 (aref vs 0))
  28.            (let ((d (digit-char-p (aref vs 1))))
  29.          (and d (<= 6 d))))
  30.       (pushnew :cmu16 *features*))))
  31.  
  32. #+CLISP
  33. (eval-when (compile load eval)
  34.   (when (find-symbol "PRINT-UNREADABLE-OBJECT" "LISP")
  35.     (pushnew :have-print-unreadable-object *features*)
  36. ) )
  37.  
  38. ;;;-------------------------------------------------------------------------
  39. ;;; Declarations
  40. ;;;-------------------------------------------------------------------------
  41.  
  42. ;;; fix a bug in kcl's RATIONAL...
  43. ;;;   redefine both the function and the type.
  44.  
  45. #+(or kcl ibcl)
  46. (progn
  47.   (defun rational (x)
  48.     (if (rationalp x)
  49.     x
  50.     (lisp:rational x)))
  51.   (deftype rational (&optional l u) `(lisp:rational ,l ,u)))
  52.  
  53. ;;; DECLAIM
  54.  
  55. #-clx-ansi-common-lisp
  56. (defmacro declaim (&rest decl-specs)
  57.   (if (cdr decl-specs)
  58.       `(progn
  59.      ,@(mapcar #'(lambda (decl-spec) `(proclaim ',decl-spec))
  60.            decl-specs))
  61.     `(proclaim ',(car decl-specs))))
  62.  
  63. ;;; VALUES value1 value2 ... -- Documents the values returned by the function.
  64.  
  65. #-lispm
  66. (declaim (declaration values))
  67.  
  68. ;;; ARGLIST arg1 arg2 ... -- Documents the arglist of the function.  Overrides
  69. ;;; the documentation that might get generated by the real arglist of the
  70. ;;; function.
  71.  
  72. #-(or lispm lcl3.0)
  73. (declaim (declaration arglist))
  74.  
  75. ;;; DYNAMIC-EXTENT var -- Tells the compiler that the rest arg var has
  76. ;;; dynamic extent and therefore can be kept on the stack and not copied to
  77. ;;; the heap, even though the value is passed out of the function.
  78.  
  79. #-(or clx-ansi-common-lisp lcl3.0)
  80. (declaim (declaration dynamic-extent))
  81.  
  82. ;;; IGNORABLE var -- Tells the compiler that the variable might or might not be used.
  83.  
  84. #-clx-ansi-common-lisp
  85. (declaim (declaration ignorable))
  86.  
  87. ;;; ARRAY-REGISTER var1 var2 ... -- The variables mentioned are locals (not
  88. ;;; args) that hold vectors.  
  89.  
  90. #-Genera 
  91. (declaim (declaration array-register))
  92.  
  93. ;;; INDENTATION argpos1 arginden1 argpos2 arginden2 --- Tells the lisp editor how to
  94. ;;; indent calls to the function or macro containing the declaration.  
  95.  
  96. #-genera
  97. (declaim (declaration indentation))
  98.  
  99. ;;;-------------------------------------------------------------------------
  100. ;;; Declaration macros
  101. ;;;-------------------------------------------------------------------------
  102.  
  103. ;;; WITH-VECTOR (variable type) &body body --- ensures the variable is a local
  104. ;;; and then does a type declaration and array register declaration
  105. (defmacro with-vector ((var type) &body body)
  106.   `(let ((,var ,var))
  107.      (declare (type ,type ,var)
  108.           (array-register ,var))
  109.      ,@body))
  110.  
  111. ;;; WITHIN-DEFINITION (name type) &body body --- Includes definitions for
  112. ;;; Meta-.
  113.  
  114. #+lispm
  115. (defmacro within-definition ((name type) &body body)
  116.   `(zl:local-declare
  117.      ((sys:function-parent ,name ,type))
  118.      (sys:record-source-file-name ',name ',type)
  119.      ,@body))
  120.  
  121. #-lispm
  122. (defmacro within-definition ((name type) &body body)
  123.   (declare (ignore name type))
  124.   `(progn ,@body))
  125.  
  126.  
  127. ;;;-------------------------------------------------------------------------
  128. ;;; CLX can maintain a mapping from X server ID's to local data types.  If
  129. ;;; one takes the view that CLX objects will be instance variables of
  130. ;;; objects at the next higher level, then PROCESS-EVENT will typically map
  131. ;;; from resource-id to higher-level object.  In that case, the lower-level
  132. ;;; CLX mapping will almost never be used (except in rare cases like
  133. ;;; query-tree), and only serve to consume space (which is difficult to
  134. ;;; GC), in which case always-consing versions of the make-<mumble>s will
  135. ;;; be better.  Even when maps are maintained, it isn't clear they are
  136. ;;; useful for much beyond xatoms and windows (since almost nothing else
  137. ;;; ever comes back in events).
  138. ;;;--------------------------------------------------------------------------
  139. (defconstant *clx-cached-types*
  140.          '( drawable
  141.         window
  142.         pixmap
  143. ;        gcontext
  144.         cursor
  145.         colormap
  146.         font))
  147.  
  148. (defmacro resource-id-map-test ()
  149.   #+excl '#'equal
  150.   #-excl '#'eql)
  151.                     ; (eq fixnum fixnum) is not guaranteed.
  152. (defmacro atom-cache-map-test ()
  153.   #+excl '#'equal
  154.   #-excl '#'eq)
  155.  
  156. (defmacro keysym->character-map-test ()
  157.   #+excl '#'equal
  158.   #-excl '#'eql)
  159.  
  160. ;;; You must define this to match the real byte order.  It is used by
  161. ;;; overlapping array and image code.
  162.  
  163. #+(or lispm vax little-endian i386 Minima)
  164. (eval-when (eval compile load)
  165.   (pushnew :clx-little-endian *features*))
  166.  
  167. #+lcl3.0
  168. (eval-when (compile eval load)
  169.   (ecase lucid::machine-endian
  170.     (:big nil)
  171.     (:little (pushnew :clx-little-endian *features*))))
  172.  
  173. #+cmu
  174. (eval-when (compile eval load)
  175.   (ecase #.(c:backend-byte-order c:*backend*)
  176.     (:big-endian)
  177.     (:little-endian (pushnew :clx-little-endian *features*))))
  178.  
  179. #+CLISP
  180. (eval-when (compile eval load)
  181.   (unless system::*big-endian* (pushnew :clx-little-endian *features*))
  182. )
  183.  
  184. ;;; Steele's Common-Lisp states:  "It is an error if the array specified
  185. ;;; as the :displaced-to argument  does not have the same :element-type
  186. ;;; as the array being created" If this is the case on your lisp, then
  187. ;;; leave the overlapping-arrays feature turned off.  Lisp machines
  188. ;;; (Symbolics TI and LMI) don't have this restriction, and allow arrays
  189. ;;; with different element types to overlap.  CLX will take advantage of
  190. ;;; this to do fast array packing/unpacking when the overlapping-arrays
  191. ;;; feature is enabled.
  192.  
  193. #+(and clx-little-endian lispm)
  194. (eval-when (eval compile load)
  195.   (pushnew :clx-overlapping-arrays *features*))
  196.  
  197. #+(and clx-overlapping-arrays genera)
  198. (progn
  199. (deftype overlap16 () '(unsigned-byte 16))
  200. (deftype overlap32 () '(signed-byte 32))
  201. )
  202.  
  203. #+(and clx-overlapping-arrays (or explorer lambda cadr))
  204. (progn
  205. (deftype overlap16 () '(unsigned-byte 16))
  206. (deftype overlap32 () '(unsigned-byte 32))
  207. )
  208.  
  209. (deftype buffer-bytes () `(simple-array (unsigned-byte 8) (*)))
  210.  
  211. #+clx-overlapping-arrays
  212. (progn
  213. (deftype buffer-words () `(vector overlap16))
  214. (deftype buffer-longs () `(vector overlap32))
  215. )
  216.  
  217. ;;; This defines a type which is a subtype of the integers.
  218. ;;; This type is used to describe all variables that can be array indices.
  219. ;;; It is here because it is used below.
  220. ;;; This is inclusive because start/end can be 1 past the end.
  221. (deftype array-index () `(integer 0 ,array-dimension-limit))
  222.  
  223.  
  224. ;; this is the best place to define these?
  225.  
  226. #-Genera
  227. (progn
  228.  
  229. (defun make-index-typed (form)
  230.   (if (constantp form) form `(the array-index ,form)))
  231.  
  232. (defun make-index-op (operator args)
  233.   `(the array-index
  234.     (values 
  235.       ,(case (length args)
  236.          (0 `(,operator))
  237.          (1 `(,operator
  238.           ,(make-index-typed (first args))))
  239.          (2 `(,operator
  240.           ,(make-index-typed (first args))
  241.           ,(make-index-typed (second args))))
  242.          (otherwise
  243.            `(,operator
  244.          ,(make-index-op operator (subseq args 0 (1- (length args))))
  245.          ,(make-index-typed (first (last args)))))))))
  246.  
  247. (defmacro index+ (&rest numbers) (make-index-op '+ numbers))
  248. (defmacro index-logand (&rest numbers) (make-index-op 'logand numbers))
  249. (defmacro index-logior (&rest numbers) (make-index-op 'logior numbers))
  250. (defmacro index- (&rest numbers) (make-index-op '- numbers))
  251. (defmacro index* (&rest numbers) (make-index-op '* numbers))
  252.  
  253. (defmacro index1+ (number) (make-index-op '1+ (list number)))
  254. (defmacro index1- (number) (make-index-op '1- (list number)))
  255.  
  256. (defmacro index-incf (place &optional (delta 1))
  257.   (make-index-op 'incf (list place delta)))
  258. (defmacro index-decf (place &optional (delta 1))
  259.   (make-index-op 'decf (list place delta)))
  260.  
  261. (defmacro index-min (&rest numbers) (make-index-op 'min numbers))
  262. (defmacro index-max (&rest numbers) (make-index-op 'max numbers))
  263.  
  264. (defmacro index-floor (number divisor)
  265.   (make-index-op 'floor (list number divisor)))
  266. (defmacro index-ceiling (number divisor)
  267.   (make-index-op 'ceiling (list number divisor)))
  268. (defmacro index-truncate (number divisor)
  269.   (make-index-op 'truncate (list number divisor)))
  270.  
  271. (defmacro index-mod (number divisor)
  272.   (make-index-op 'mod (list number divisor)))
  273.  
  274. (defmacro index-ash (number count)
  275.   (make-index-op 'ash (list number count)))
  276.  
  277. (defmacro index-plusp (number) `(plusp (the array-index ,number)))
  278. (defmacro index-zerop (number) `(zerop (the array-index ,number)))
  279. (defmacro index-evenp (number) `(evenp (the array-index ,number)))
  280. (defmacro index-oddp  (number) `(oddp  (the array-index ,number)))
  281.  
  282. (defmacro index> (&rest numbers)
  283.   `(> ,@(mapcar #'make-index-typed numbers)))
  284. (defmacro index= (&rest numbers)
  285.   `(= ,@(mapcar #'make-index-typed numbers)))
  286. (defmacro index< (&rest numbers)
  287.   `(< ,@(mapcar #'make-index-typed numbers)))
  288. (defmacro index>= (&rest numbers)
  289.   `(>= ,@(mapcar #'make-index-typed numbers)))
  290. (defmacro index<= (&rest numbers)
  291.   `(<= ,@(mapcar #'make-index-typed numbers)))
  292.  
  293. )
  294.  
  295. #+Genera
  296. (progn
  297.  
  298. (defmacro index+ (&rest numbers) `(+ ,@numbers))
  299. (defmacro index-logand (&rest numbers) `(logand ,@numbers))
  300. (defmacro index-logior (&rest numbers) `(logior ,@numbers))
  301. (defmacro index- (&rest numbers) `(- ,@numbers))
  302. (defmacro index* (&rest numbers) `(* ,@numbers))
  303.  
  304. (defmacro index1+ (number) `(1+ ,number))
  305. (defmacro index1- (number) `(1- ,number))
  306.  
  307. (defmacro index-incf (place &optional (delta 1)) `(setf ,place (index+ ,place ,delta)))
  308. (defmacro index-decf (place &optional (delta 1)) `(setf ,place (index- ,place ,delta)))
  309.  
  310. (defmacro index-min (&rest numbers) `(min ,@numbers))
  311. (defmacro index-max (&rest numbers) `(max ,@numbers))
  312.  
  313. (defun positive-power-of-two-p (x)
  314.   (when (symbolp x)
  315.     (multiple-value-bind (constantp value) (lt:named-constant-p x)
  316.       (when constantp (setq x value))))
  317.   (and (typep x 'fixnum) (plusp x) (zerop (logand x (1- x)))))
  318.  
  319. (defmacro index-floor (number divisor)
  320.   (cond ((eql divisor 1) number)
  321.     ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-floor))
  322.      `(si:%fixnum-floor ,number ,divisor))
  323.     (t `(floor ,number ,divisor))))
  324.  
  325. (defmacro index-ceiling (number divisor)
  326.   (cond ((eql divisor 1) number)
  327.     ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-ceiling))
  328.      `(si:%fixnum-ceiling ,number ,divisor))
  329.     (t `(ceiling ,number ,divisor))))
  330.  
  331. (defmacro index-truncate (number divisor)
  332.   (cond ((eql divisor 1) number)
  333.     ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-floor))
  334.      `(si:%fixnum-floor ,number ,divisor))
  335.     (t `(truncate ,number ,divisor))))
  336.  
  337. (defmacro index-mod (number divisor)
  338.   (cond ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-mod))
  339.      `(si:%fixnum-mod ,number ,divisor))
  340.     (t `(mod ,number ,divisor))))
  341.  
  342. (defmacro index-ash (number count)
  343.   (cond ((eql count 0) number)
  344.     ((and (typep count 'fixnum) (minusp count) (fboundp 'si:%fixnum-floor))
  345.      `(si:%fixnum-floor ,number ,(expt 2 (- count))))
  346.     ((and (typep count 'fixnum) (plusp count) (fboundp 'si:%fixnum-multiply))
  347.      `(si:%fixnum-multiply ,number ,(expt 2 count)))
  348.     (t `(ash ,number ,count))))
  349.  
  350. (defmacro index-plusp (number) `(plusp ,number))
  351. (defmacro index-zerop (number) `(zerop ,number))
  352. (defmacro index-evenp (number) `(evenp ,number))
  353. (defmacro index-oddp  (number) `(oddp  ,number))
  354.  
  355. (defmacro index> (&rest numbers) `(> ,@numbers))
  356. (defmacro index= (&rest numbers) `(= ,@numbers))
  357. (defmacro index< (&rest numbers) `(< ,@numbers))
  358. (defmacro index>= (&rest numbers) `(>= ,@numbers))
  359. (defmacro index<= (&rest numbers) `(<= ,@numbers))
  360.  
  361. )
  362.  
  363. ;;;; Stuff for BUFFER definition
  364.  
  365. (defconstant *replysize* 32.)
  366.  
  367. ;; used in defstruct initializations to avoid compiler warnings
  368. (defvar *empty-bytes* (make-sequence 'buffer-bytes 0))
  369. (declaim (type buffer-bytes *empty-bytes*))
  370. #+clx-overlapping-arrays
  371. (progn
  372. (defvar *empty-words* (make-sequence 'buffer-words 0))
  373. (declaim (type buffer-words *empty-words*))
  374. )
  375. #+clx-overlapping-arrays
  376. (progn
  377. (defvar *empty-longs* (make-sequence 'buffer-longs 0))
  378. (declaim (type buffer-longs *empty-longs*))
  379. )
  380.  
  381. (defstruct (reply-buffer (:conc-name reply-) (:constructor make-reply-buffer-internal)
  382.              (:copier nil) (:predicate nil))
  383.   (size 0 :type array-index)            ;Buffer size
  384.   ;; Byte (8 bit) input buffer
  385.   (ibuf8 *empty-bytes* :type buffer-bytes)
  386.   ;; Word (16bit) input buffer
  387.   #+clx-overlapping-arrays
  388.   (ibuf16 *empty-words* :type buffer-words)
  389.   ;; Long (32bit) input buffer
  390.   #+clx-overlapping-arrays
  391.   (ibuf32 *empty-longs* :type buffer-longs)
  392.   (next nil #-explorer :type #-explorer (or null reply-buffer))
  393.   (data-size 0 :type array-index)
  394.   )
  395.  
  396. (defconstant *buffer-text16-size* 256)
  397. (deftype buffer-text16 () `(simple-array (unsigned-byte 16) (,*buffer-text16-size*)))
  398.  
  399. ;; These are here because.
  400.  
  401. (defparameter *xlib-package* (find-package :xlib))
  402.  
  403. (defun xintern (&rest parts)
  404.   (intern (apply #'concatenate 'string (mapcar #'string parts)) *xlib-package*))
  405.  
  406. (defparameter *keyword-package* (find-package :keyword))
  407.  
  408. (defun kintern (name)
  409.   (intern (string name) *keyword-package*))
  410.  
  411. ;;; Pseudo-class mechanism.
  412.  
  413. (eval-when (eval compile load)
  414. (defvar *def-clx-class-use-defclass* #+Genera t #-Genera nil
  415.   "Controls whether DEF-CLX-CLASS uses DEFCLASS.  
  416.    If it is a list, it is interpreted by DEF-CLX-CLASS to be a list of type names
  417.    for which DEFCLASS should be used. 
  418.    If it is not a list, then DEFCLASS is always used.
  419.    If it is NIL, then DEFCLASS is never used, since NIL is the empty list.")
  420.  
  421. ;;************
  422. #-(and CLISP (not PCL)) ;; You may remove this line for CLISP with native CLOS.
  423. (setq *def-clx-class-use-defclass* '(window drawable pixmap))
  424. #+pcl (setq pcl::*defclass-times*   '(compile load eval))
  425. )
  426.  
  427. (defmacro def-clx-class ((name &rest options) &body slots)
  428.   (if (or (not (listp *def-clx-class-use-defclass*))
  429.       (member name *def-clx-class-use-defclass*))
  430.       (let ((clos-package #+clx-ansi-common-lisp
  431.               (find-package :common-lisp)
  432.               #-clx-ansi-common-lisp
  433.               (or (find-package :pcl) ; *** switched ***
  434.                   (find-package :clos)
  435.                   (let ((lisp-pkg (find-package :lisp)))
  436.                 (and (find-symbol (string 'defclass) lisp-pkg)
  437.                      lisp-pkg))))
  438.         (constructor t)
  439.         (constructor-args t)
  440.         (include nil)
  441.         (print-function nil)
  442.         (copier t)
  443.         (predicate t))
  444.     (dolist (option options)
  445.       (ecase (pop option)
  446.         (:constructor
  447.           (setf constructor (pop option))
  448.           (setf constructor-args (if (null option) t (pop option))))
  449.         (:include
  450.           (setf include (pop option)))
  451.         (:print-function
  452.           (setf print-function (pop option)))
  453.         (:copier
  454.           (setf copier (pop option)))
  455.         (:predicate
  456.           (setf predicate (pop option)))))
  457.     (flet ((cintern (&rest symbols)
  458.          (intern (apply #'concatenate 'simple-string
  459.                 (mapcar #'symbol-name symbols))
  460.              *package*))
  461.            (kintern (symbol)
  462.             (intern (symbol-name symbol) (find-package :keyword)))
  463.            (closintern (symbol)
  464.          (intern (symbol-name symbol) clos-package)))
  465.       (when (eq constructor t)
  466.         (setf constructor (cintern 'make- name)))
  467.       (when (eq copier t)
  468.         (setf copier (cintern 'copy- name)))
  469.       (when (eq predicate t)
  470.         (setf predicate (cintern name '-p)))
  471.       (when include
  472.         (setf slots (append (get include 'def-clx-class) slots)))
  473.       (let* ((n-slots (length slots))
  474.          (slot-names (make-list n-slots))
  475.          (slot-initforms (make-list n-slots))
  476.          (slot-types (make-list n-slots)))
  477.         (dotimes (i n-slots)
  478.           (let ((slot (elt slots i)))
  479.         (setf (elt slot-names i) (pop slot))
  480.         (setf (elt slot-initforms i) (pop slot))
  481.         (setf (elt slot-types i) (getf slot :type t))))
  482.         `(progn
  483.  
  484.            (eval-when (compile load eval)
  485.          (setf (get ',name 'def-clx-class) ',slots))
  486.  
  487.            ;; From here down are the system-specific expansions:
  488.  
  489.            (within-definition (,name def-clx-class)
  490.          (,(closintern 'defclass)
  491.           ,name ,(and include `(,include))
  492.           (,@(map 'list
  493.               #'(lambda (slot-name slot-initform slot-type)
  494.                   `(,slot-name
  495.                 :initform ,slot-initform :type ,slot-type
  496.                 :accessor ,(cintern name '- slot-name)
  497.                 ,@(when (and constructor
  498.                          (or (eq constructor-args t)
  499.                          (member slot-name
  500.                              constructor-args)))
  501.                     `(:initarg ,(kintern slot-name)))
  502.                 ))
  503.               slot-names slot-initforms slot-types)))
  504.          ,(when constructor
  505.             (if (eq constructor-args t)
  506.             `(defun ,constructor (&rest args)
  507.                (apply #',(closintern 'make-instance)
  508.                   ',name args))
  509.             `(defun ,constructor ,constructor-args
  510.                (,(closintern 'make-instance) ',name
  511.                 ,@(mapcan #'(lambda (slot-name)
  512.                       (and (member slot-name slot-names)
  513.                            `(,(kintern slot-name) ,slot-name)))
  514.                       constructor-args)))))
  515.          ,(when predicate
  516.             #+(or allegro pcl)
  517.             `(progn
  518.                (,(closintern 'defmethod) ,predicate (object)
  519.              (declare (ignore object))
  520.              nil)
  521.                (,(closintern 'defmethod) ,predicate ((object ,name))
  522.              t))
  523.             #-(or allegro pcl)
  524.             `(defun ,predicate (object)
  525.                (typep object ',name)))
  526.          ,(when copier
  527.             `(,(closintern 'defmethod) ,copier ((.object. ,name))
  528.               (,(closintern 'with-slots) ,slot-names .object.
  529.                (,(closintern 'make-instance) ',name
  530.             ,@(mapcan #'(lambda (slot-name)
  531.                       `(,(kintern slot-name) ,slot-name))
  532.                   slot-names)))))
  533.          ,(when print-function
  534.             `(,(closintern 'defmethod)
  535.               ,(closintern 'print-object)
  536.               ((object ,name) stream)
  537.               (,print-function object stream 0))))))))
  538.       `(within-definition (,name def-clx-class)
  539.      (defstruct (,name ,@options)
  540.        ,@slots))))
  541.  
  542. #+Genera
  543. (progn
  544.   (scl:defprop def-clx-class "CLX Class" si:definition-type-name)
  545.   (scl:defprop def-clx-class zwei:defselect-function-spec-finder
  546.            zwei:definition-function-spec-finder))
  547.  
  548.  
  549. ;; We need this here so we can define DISPLAY for CLX.
  550. ;;
  551. ;; This structure is :INCLUDEd in the DISPLAY structure.
  552. ;; Overlapping (displaced) arrays are provided for byte
  553. ;; half-word and word access on both input and output.
  554. ;;
  555. (def-clx-class (buffer (:constructor nil) (:copier nil) (:predicate nil))
  556.   ;; Lock for multi-processing systems
  557.   (lock (make-process-lock "CLX Buffer Lock"))
  558.   #-excl (output-stream nil :type (or null stream))
  559.   #+excl (output-stream -1 :type fixnum)
  560.   ;; Buffer size
  561.   (size 0 :type array-index)
  562.   (request-number 0 :type (unsigned-byte 16))
  563.   ;; Byte position of start of last request
  564.   ;; used for appending requests and error recovery
  565.   (last-request nil :type (or null array-index))
  566.   ;; Byte position of start of last flushed request
  567.   (last-flushed-request nil :type (or null array-index))
  568.   ;; Current byte offset
  569.   (boffset 0 :type array-index)
  570.   ;; Byte (8 bit) output buffer
  571.   (obuf8 *empty-bytes* :type buffer-bytes)
  572.   ;; Word (16bit) output buffer
  573.   #+clx-overlapping-arrays
  574.   (obuf16 *empty-words* :type buffer-words)
  575.   ;; Long (32bit) output buffer
  576.   #+clx-overlapping-arrays
  577.   (obuf32 *empty-longs* :type buffer-longs)
  578.   ;; Holding buffer for 16-bit text
  579.   (tbuf16 (make-sequence 'buffer-text16 *buffer-text16-size* :initial-element 0))
  580.   ;; Probably EQ to Output-Stream
  581.   #-excl (input-stream nil :type (or null stream))
  582.   #+excl (input-stream -1 :type fixnum)
  583.   ;; T when the host connection has gotten errors
  584.   (dead nil :type (or null (not null)))
  585.   ;; T makes buffer-flush a noop.  Manipulated with with-buffer-flush-inhibited.
  586.   (flush-inhibit nil :type (or null (not null)))
  587.   
  588.   ;; Change these functions when using shared memory buffers to the server
  589.   ;; Function to call when writing the buffer
  590.   (write-function 'buffer-write-default)
  591.   ;; Function to call when flushing the buffer
  592.   (force-output-function 'buffer-force-output-default)
  593.   ;; Function to call when closing a connection
  594.   (close-function 'buffer-close-default)
  595.   ;; Function to call when reading the buffer
  596.   (input-function 'buffer-read-default)
  597.   ;; Function to call to wait for data to be input
  598.   (input-wait-function 'buffer-input-wait-default)
  599.   ;; Function to call to listen for input data
  600.   (listen-function 'buffer-listen-default)
  601.  
  602.   #+Genera (debug-io nil :type (or null stream))
  603.   ) 
  604.  
  605. ;;-----------------------------------------------------------------------------
  606. ;; Printing routines.
  607. ;;-----------------------------------------------------------------------------
  608.  
  609. #-(or clx-ansi-common-lisp Genera CMU (and CLISP have-print-unreadable-object))
  610. (defun print-unreadable-object-function (object stream type identity function)
  611.   (declare #+lispm
  612.        (sys:downward-funarg function))
  613.   (princ "#<" stream)
  614.   (when type
  615.     (let ((type (type-of object))
  616.       (pcl-package (find-package :pcl)))
  617.       ;; Handle pcl type-of lossage
  618.       (when (and pcl-package
  619.          (symbolp type)
  620.          (eq (symbol-package type) pcl-package)
  621.          (string-equal (symbol-name type) "STD-INSTANCE"))
  622.     (setq type
  623.           (funcall (intern (symbol-name 'class-name) pcl-package)
  624.                (funcall (intern (symbol-name 'class-of) pcl-package)
  625.                 object))))
  626.       (prin1 type stream)))
  627.   (when (and type function) (princ " " stream))
  628.   (when function (funcall function))
  629.   (when (and (or type function) identity) (princ " " stream))
  630.   (when identity
  631.     #-CLISP (princ "???" stream)
  632.     #+CLISP (format stream "#x~8,'0X" (sys::address-of object))
  633.   )
  634.   (princ ">" stream)
  635.   nil)
  636.   
  637. #-(or clx-ansi-common-lisp Genera CMU (and CLISP have-print-unreadable-object))
  638. (defmacro print-unreadable-object
  639.       ((object stream &key type identity) &body body)
  640.   (if body
  641.       `(flet ((.print-unreadable-object-body. () ,@body))
  642.      (print-unreadable-object-function
  643.        ,object ,stream ,type ,identity #'.print-unreadable-object-body.))
  644.     `(print-unreadable-object-function ,object ,stream ,type ,identity nil)))
  645.  
  646.  
  647. ;;-----------------------------------------------------------------------------
  648. ;; Image stuff
  649. ;;-----------------------------------------------------------------------------
  650.  
  651. (defconstant *image-bit-lsb-first-p*
  652.          #+clx-little-endian t
  653.          #-clx-little-endian nil)
  654.  
  655. (defconstant *image-byte-lsb-first-p*
  656.          #+clx-little-endian t
  657.          #-clx-little-endian nil)
  658.  
  659. (defconstant *image-unit* 32)
  660.  
  661. (defconstant *image-pad* 32)
  662.  
  663.  
  664. ;;-----------------------------------------------------------------------------
  665. ;; Foreign Functions
  666. ;;-----------------------------------------------------------------------------
  667.  
  668. #+(and lucid apollo (not lcl3.0))
  669. (lucid::define-foreign-function '(connect-to-server "connect_to_server")
  670.   '((:val host    :string)
  671.     (:val display :integer32))
  672.   :integer32)
  673.  
  674. #+(and lucid (not apollo) (not lcl3.0))
  675. (lucid::define-c-function connect-to-server (host display)
  676.   :result-type :integer)
  677.  
  678. #+lcl3.0
  679. (lucid::def-foreign-function
  680.     (connect-to-server 
  681.       (:language :c)
  682.       (:return-type :signed-32bit))
  683.   (host :simple-string)
  684.   (display :signed-32bit))
  685.  
  686. #+(and CMU (not cmu16))
  687. (ext:def-c-routine ("connect_to_server" connect-to-server) (ext:int)
  688.   (host system:null-terminated-string)
  689.   (port ext:int))
  690.  
  691. #+cmu16
  692. (alien:def-alien-routine ("connect_to_server" xlib::connect-to-server)
  693.                c-call:int
  694.     (host c-call:c-string)
  695.     (port c-call:int))
  696.